home *** CD-ROM | disk | FTP | other *** search
- Path: news.mira.net.au!news
- From: davidw@werple.net.au (David White)
- Newsgroups: comp.lang.c++
- Subject: Re: [] overload..(newbie in distress)
- Date: 21 Jan 1996 09:09:56 +1100
- Organization: Werple Internet, Melbourne
- Message-ID: <4drp7k$bj1@werple.net.au>
- References: <DLGppJ.31C@undergrad.math.uwaterloo.ca>
- NNTP-Posting-Host: werple.mira.net.au
-
- tthiraku@landen.math.uwaterloo.ca (Thanou Thirakul) writes:
-
- >Hi..
-
- >I'm currently stuck on how to overload [] operator such that
- >it does two different tasks..
-
-
- >case 1:
-
- >// A is an instance of a class that contains a linkist.
-
- > A[5] = val; // store val into the fifth node of a linklist.
-
- For this you can use a member function such as:
-
- T &operator[](int i);
-
- If the linked list needs to know when one of its items has changed, you
- need something more elaborate. This can be done by returning an instance
- of a helper class instead of a T&; the helper object then receives the
- assignment operation and can notify the linked list.
-
- > val = A[5] ; // returns the value of the fifth node of a linklist.
-
- And for this you can use:
-
- T operator[](int i) const;
-
- >I was wondering how can C++ differentiate these two senerios?
-
-
- David White
- davidw@werple.mira.net.au
-